﻿using System;

namespace CSW.Framework.Common.Utils
{
    /// <summary>
    /// NumberHelper
    /// </summary>
    public class NumberHelper
    {
        /// <summary>
        /// Compares two double values for equality.
        /// </summary>
        /// <param name="double1">The first double.</param>
        /// <param name="double2">The second double.</param>
        /// <returns><c>true</c> if the values are equal; otherwise, <c>false</c>.</returns>
        public static bool DoublesAreEqual(double double1, double double2)
        {
            return (Math.Abs(double1 - double2) < double.Epsilon);
        }

        /// <summary>
        /// Determines whether the type is a numeric type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns><c>true</c> if the type is a numeric type; otherwise, <c>false</c>.</returns>
        public static bool IsNumericType(Type type)
        {
            Guard.ArgumentNotNull(type, "type");

            return (type == typeof(int) ||
                    type == typeof(int?) ||
                    type == typeof(long) ||
                    type == typeof(long?) ||
                    type == typeof(short) ||
                    type == typeof(short?) ||
                    type == typeof(float) ||
                    type == typeof(float?) ||
                    type == typeof(double) ||
                    type == typeof(double?) ||
                    type == typeof(uint) ||
                    type == typeof(uint?) ||
                    type == typeof(ulong) ||
                    type == typeof(ulong?) ||
                    type == typeof(ushort) ||
                    type == typeof(ushort?) ||
                    type == typeof(decimal) ||
                    type == typeof(decimal?));
        }
    }
}
